<template>
  <div class="app-container">
    <el-form
      class="formList"
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
    >
      <el-row>
        <el-form-item label="选择任务" prop="storeId">
          <el-select style="width:278px"
            v-model="queryParams.taskId"
            placeholder="请选择任务"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in storeInFoOptions"
              :key="dict.taskId"
              :label="dict.taskName"
              :value="dict.taskId"
            />
          </el-select>
        </el-form-item>

        <!-- <el-form-item label="状态" prop="dataStatus">
          <el-select
            v-model="queryParams.dataStatus"
            placeholder="请选择状态"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item> -->

        <el-form-item style="margin-left: 22px">
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-row>
    </el-form>

    <el-row class="row-mbinfo">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['device:brand:add']"
          >新增</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5" style="margin-left: 10px">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['device:brand:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5" style="margin-left: 10px">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['device:brand:remove']"
          >删除</el-button
        >
      </el-col> -->

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <div class="divTable">
      <el-table
        border
        v-loading="loading"
        :data="brandList"
      >
    
      <el-table-column label="会员名称" align="center" prop="customerName" />

      <el-table-column label="会员等级" align="center" prop="levelName" />

      <el-table-column label="手机号" align="center" prop="phone" />

        <el-table-column label="任务Icon" align="center" prop="taskIcon">
          <template slot-scope="scope">
            <el-image
              v-if="scope.row.taskIcon != null && scope.row.taskIcon != ''"
              slot="reference"
              :src="scope.row.taskIcon"
              class="image-rows"
              :preview-src-list="[scope.row.taskIcon]"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column label="任务名称" align="center" prop="taskName" />

        <el-table-column label="任务简介" align="center" prop="taskBrief" />

       
        <el-table-column label="开始时间-结束时间"
          align="center"
          prop="timeStr"
          width="260px"
          :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startDate, "{y}年{m}月{d}日") }}-
              {{ parseTime(scope.row.endDate, "{y}年{m}月{d}日") }}</span>
          </template>
        </el-table-column>
       
        <el-table-column label="任务奖励" align="center" prop="reward" />

        <el-table-column label="完成时间"
          align="center"
          prop="createTime"
          width="180"
          sortable>
          <template slot-scope="scope">
            <span>{{
              parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{i}:{s}")
            }}</span>
          </template>
        </el-table-column>
     

        <!-- <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['device:brand:edit']"
              >修改</el-button
            >
            <el-button
              v-if="scope.row.dataStatus == '0'"
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['device:brand:remove']"
              >删除</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
 
  
  </div>
</template>

<script>
import {
  selectask,
  listTaskRecommend
} from "@/api/service/task";

import imageArraySize from "@/components/ImageUpload/imageArraySize";
export default {
  name: "Task",
  components: {
    imageArraySize,
   
  },
  data() {
    return {

      storeInFoOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //选中数组的名字
      names: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 品牌/系列表格数据
      brandList: [],
      // 弹出层标题
      title: "",
      q:null,
      // 是否显示弹出层
      open: false,
      // 用于类别关联的分类显示
      dialogVisible: false,
      //常用状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskId:null,
      },
    
      // 表单参数
      form: {
        dialogImageUrl: "",
        dataPriority: "",
      },
      // 表单校验
   
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  created() {
    console.log(this.$route.query.backName)
   

   
    // if(this.$route.query.backName != undefined ){
    //   this.queryParams.taskId = this.$route.query.backName*1
    // }
   
 

    // this.getList();
    // this.getDicts("sys_data_status").then((response) => {
    //   this.statusOptions = response.data;
    // });
    // selectask().then((response) => {
    //   this.storeInFoOptions = response.data || [];
    // });

  },
  activated () {
    if(this.$route.query.backName != undefined ){
      this.queryParams.taskId = this.$route.query.backName*1
    }
   
    this.getList();
    this.getDicts("sys_data_status").then((response) => {
      this.statusOptions = response.data;
    });
    selectask().then((response) => {
      this.storeInFoOptions = response.data || [];
    });
  },
  methods: {
    // dataPriorityInput(value) {
    //   let js = value + "";
    //   return js.replace(/^(0+)|[^\d]+/g, "");
    // },
    /** 查询列表 */
    getList() {
      this.loading = true;
 
      listTaskRecommend(this.queryParams).then((response) => {
        this.brandList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
  
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    p(s) {
      return s < 10 ? "0" + s : s;
    },

    // 关联的取消按钮
    cancelTask() {
      this.openTask = false;
      this.reset();
    },
    handleChange(value) {
      console.log(value);
    },
    getSTime(val) {
      //手动赋值，使其通过校验

      const d = new Date(val[0]);
      const resDate =
        d.getFullYear() +
        "-" +
        this.p(d.getMonth() + 1) +
        "-" +
        this.p(d.getDate());
      const resTime =
        this.p(d.getHours()) +
        ":" +
        this.p(d.getMinutes()) +
        ":" +
        this.p(d.getSeconds());
      this.form.startDate = resDate + " " + resTime;
      const c = new Date(val[1]);
      const resDatec =
        c.getFullYear() +
        "-" +
        this.p(c.getMonth() + 1) +
        "-" +
        this.p(c.getDate());
      const resTimec =
        this.p(c.getHours()) +
        ":" +
        this.p(c.getMinutes()) +
        ":" +
        this.p(c.getSeconds());
      this.form.endDate = resDatec + " " + resTimec;
    },

    handleSportRecord(row) {
      this.$router.push({ path: "/push/activity/detail/" + row.taskId });
    },

    // 表单重置
    reset() {
      this.form = {
        deviceName: null,
        logoUrl: null,
        deviceTask: null,
        taskIcon: null,
        dataPriority: 10,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryParams");
      this.queryParams.taskId = null;
      this.handleQuery();
    },


  },
};
</script>
<style lang="scss" scoped>
.treeOne {
  display: inline-block;
  margin-right: 200px;
}

.treeTwo {
  display: inline-block;
}

.image-rows {
  width: 60px;
  height: 60px;
}
</style>
